﻿/* Copyright 2012 NARI-TECH */
#include <iostream.h>
#include <math.h>

void main() {
  double x0 = 0.5;
  double x;
  int i;
  double error = 0.001;
  double y;
  double y0 = (2*x0-exp(-x0));  //  f(x)=2*x-e^(-x)
  double y_d = 2+(exp(-x0));   //  f(x)'=2+e^(-x)
  for (i = 0;i < 100;i++) {
        x = x0-(y0/y_d);
        y = (2*x-exp(-x));
        if (fabs(y-y0) <error)
        break;
        y0 = y;
        x0 = x;
  }
  if (i == 100)
  cout << "达到迭代极限" << endl;
  else
  cout << "方程的近似解为x=" << x << endl;
}

